/**
 * Copyright © 2015 ChangSha 80 Network Technology Co.,Ltd All Rights Reserved
 */
package com.yiren.dbaa.module.exam.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;

import com.yiren.backstage.currency.entity.ProjectEntity;
import com.yiren.dbaa.R;
import com.yiren.dbaa.view.adapter.ExamLightDialogAdapter;

import java.util.List;

/**
 * Created by WANGRONGXIANG
 * on 2022/3/28
 * Describe 灯光选择对话框
 */
public class LightChooseDialog extends Dialog {

    private Context context;
    private List<ProjectEntity> lightProjects;  //灯光列表

    private ExamLightDialogAdapter adapter;

    public LightChooseDialog(Context context, List<ProjectEntity> lightProjects) {
        super(context, R.style.manual_command_dialog_style);
        this.context = context;
        this.lightProjects = lightProjects;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_exam_light);
        GridView gvLight = (GridView) findViewById(R.id.gv_light);
        Button btClose = (Button) findViewById(R.id.bt_close);
        btClose.setOnClickListener(v -> dismiss());
        adapter = new ExamLightDialogAdapter(context, lightProjects);
        gvLight.setAdapter(adapter);
        gvLight.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (null != onLightItemClickListener)
                    LightChooseDialog.this.dismiss();
                onLightItemClickListener.onLightItemClick(position);
            }
        });
    }

    private OnLightItemClickListener onLightItemClickListener;

    public void setOnLightItemClickListener(OnLightItemClickListener onLightItemClickListener) {
        this.onLightItemClickListener = onLightItemClickListener;
    }

    public interface OnLightItemClickListener {
        void onLightItemClick(int position);
    }

}
